iv_all_names_nofprop = c("scale(last_algorithm) + scale(first_algorithm) + scale(percent_freq)")
fprop40 = "scale(fprop40)"
fprop60 = "scale(fprop60)"

#### SENSITIVITY TEST: Using Different Birth Years For Measuring First Name Commonality ####
mod_ced40 <- lm(formula(paste(dv_ced, "~", iv_all_names_nofprop, "+", fprop40, "+", ced_controls)),
                data = ced)
mod_ced40_r2 = round(summary(mod_ced40)$adj.r.squared, 4)
mod_ced40 <- get_clusters(mod_ced40)

mod_ced60 <- lm(formula(paste(dv_ced, "~", iv_all_names_nofprop, "+", fprop60, "+", ced_controls)),
                data = ced)
mod_ced60_r2 = round(summary(mod_ced60)$adj.r.squared, 4)
mod_ced60 <- get_clusters(mod_ced60)


mod_prim40 <- lm(formula(paste(dv_prim, "~", iv_all_names_nofprop, "+", fprop40, "+", primary_controls)),
                data = primary)
mod_prim40_r2 = round(summary(mod_prim40)$adj.r.squared, 4)
mod_prim40 <- get_clusters(mod_prim40)

mod_prim60 <- lm(formula(paste(dv_prim, "~", iv_all_names_nofprop, "+", fprop60, "+", primary_controls)),
                data = primary)
mod_prim60_r2 = round(summary(mod_prim60)$adj.r.squared, 4)
mod_prim60 <- get_clusters(mod_prim60)


mod_gen40 <- lm(formula(paste(dv_gen, "~", iv_all_names_nofprop, "+", fprop40, "+", general_controls)),
                 data = general)
mod_gen40_r2 = round(summary(mod_gen40)$adj.r.squared, 4)
mod_gen40 <- get_clusters(mod_gen40)

mod_gen60 <- lm(formula(paste(dv_gen, "~", iv_all_names_nofprop, "+", fprop60, "+", general_controls)),
                 data = general)
mod_gen60_r2 = round(summary(mod_gen60)$adj.r.squared, 4)
mod_gen60 <- get_clusters(mod_gen60)

mods <- list(mod_gen40, mod_gen60, mod_prim40, mod_prim60, mod_ced40, mod_ced60)
stargazer(mods,
          type = "latex",
          title = "Relationship Between Name Fluency and Vote Share Using Different Years to Measure First Name Commonality",
          style = "ajps",
          ci = F,
          model.names = F,
          star.cutoffs = c(.05, .01, .001),
          star.char = c("*", "**", "***"),
          notes = "Standard errors are clustered by election",
          keep = c("last_algorithm",
                   "first_algorithm",
                   "percent_freq",
                   "fprop40",
                   "fprop60"),
          covariate.labels = c("Surname Pronounceability",
                               "First Name Pronounceability",
                               "Surname Commonality",
                               "First Name Commonality (1940 data)",
                               "First Name Commonality (1960 data)"),
          add.lines=list(c("Year FE", "\\checkmark", "\\checkmark", "\\checkmark", "\\checkmark", "\\checkmark", "\\checkmark"),
                         c("County FE", "", "", "", "", "\\checkmark", "\\checkmark"),
                         c("State FE", "\\checkmark", "\\checkmark", "\\checkmark", "\\checkmark", "", ""),
                         c("Controls", "\\checkmark", "\\checkmark", "\\checkmark", "\\checkmark", "\\checkmark", "\\checkmark"),
                         c("N", get_n(mod_gen40), get_n(mod_gen60), get_n(mod_prim40), get_n(mod_prim60), get_n(mod_ced40), get_n(mod_ced60)),
                         c("Adj. R-squared", mod_gen40_r2, mod_gen60_r2, mod_prim40_r2, mod_prim60_r2, mod_ced40_r2, mod_ced60_r2)),
          align = F,
          keep.stat = c("n", "adj.rsq"),
          column.labels = c("General Elections", "Primary Elections", "Local Elections"),
          column.separate = c(2, 2, 2),
          out = "Tables/reg-name-years.tex",
          label = "tab:reg-name-years")
